package com.mioto.ld.module.log.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mioto.ld.aop.anno.BizLogAnno;
import com.mioto.ld.module.log.model.BizModuleName;
import com.mioto.ld.module.log.model.BizOperationType;
import com.mioto.ld.component.BasePager;
import com.mioto.ld.module.log.model.BizLogDTO;
import com.mioto.ld.module.log.service.IBizLogService;
import com.mioto.ld.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mioto-qinxj
 * @date 2024/5/6
 * @desc 操作日志
 */
@RestController
@RequestMapping("log")
@Api(tags = "操作日志管理")
public class BizLogController {

    @Resource
    private IBizLogService bizLogService;

    @GetMapping("/pager")
    @ApiOperation(value="分页查询操作日志",response = BizLogDTO.class)
    @BizLogAnno(operationType = BizOperationType.PAGER,moduleName = BizModuleName.BIZ_LOG)
    public ResultData pager(HttpServletRequest request, BasePager basePager){
        PageHelper.startPage(basePager.getPage(), basePager.getRows(), basePager.getSortBy());
        List<BizLogDTO> list = bizLogService.findList();
        PageInfo<BizLogDTO> pageInfo = new PageInfo<>(list);
        Map<String, Object> result = new HashMap<>(4);
        result.put("count", pageInfo.getTotal());
        result.put("list", pageInfo.getList());
        return ResultData.success(result);
    }
}
